﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Data;
using BaseUI;
using BL;
using IUI;

namespace WinUI
{
   public partial class MainForm : //Form
                                   BaseWinForm<MainPageController>, IMainPage
   {
       static private MainForm _instance = null;
       static public MainForm Instance
       {
           get
           {
               if (null == _instance)
               {
                   _instance = new MainForm();
               }

               return _instance;
           }
       }
       // обработчик события нажатия на кнопку "Admin Page"
      private event EventHandler _btnAdminClick;
      private void btnAdmin_Click(object sender, EventArgs e)
      {
          if (_btnAdminClick != null)
              _btnAdminClick(this, null);
      }
      
      private MainForm()
      {
         InitializeComponent();           
      }

      private String _userID;

      #region Реализация IMainPage
      public String UserID
      {
          get { return _userID; }
      }

      public User User
      {
          get { return User.GetByName(UserID); }
      }

      public void SetUserID(String id)
      {
          if (null == _userID)
          {              
              _userID = id;
          }
      }

      public EventHandler ClickAdminButton
      {
          get { return _btnAdminClick; }
          set { _btnAdminClick = value; }
      }

      public void OpenAdminPage()
      {
          if (User.IsAdmin)
          {
              this.Hide();

              AdminForm af = new AdminForm();
              af.ShowDialog();

           // this.Show();
          }
      }
      #endregion
       
      private void MainForm_Load(object sender, EventArgs e)
      {
          this.Hide();
          LoginForm lf = new LoginForm();
          lf.ShowDialog();
      }

      private void MainForm_Shown(object sender, EventArgs e)
      {
          if (User.IsAdmin)
          {
              btnAdmin.Enabled = true;
              btnAdmin.Visible = true;
          } 
      }


   }
}
